
package ps.mediengestaltung;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import de.tavendo.autobahn.WebSocketConnection;
import de.tavendo.autobahn.WebSocketException;
import de.tavendo.autobahn.WebSocketHandler;


public class MainActivity extends Activity {
	
	
	
	public final WebSocketConnection mConnection = new WebSocketConnection();

   @Override
   public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.main);
      
      
      final String wsuri = "ws://websocketserver.nodester.com:19572";
		
		try {
			mConnection.connect(wsuri, new WebSocketHandler() {
				
				@Override
				public void onOpen() {
					Log.d("TAG", "Status: Connected to " + wsuri);
					mConnection.sendTextMessage("Hello Server!");
				}
				
				@Override
				public void onTextMessage(String payload) {
					Log.d("TAG", "Got echo: " + payload);
				}
				
				@Override
				public void onClose(int code, String reason) {
					Log.d("TAG", "Connection lost.");
				}
			});
		} catch (WebSocketException e) {
				Log.d("TAG", e.toString());
		}
      
  }

}
